package homework;

import lesson.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu extends JPanel implements ActionListener {
    private Atm atm;
    private Icon offImg = Util.getIcon("/buttonOff.jpg");
    private JButton offBtn = new JButton(offImg);

    private Icon findImg = Util.getIcon("/buttonFind.jpg");
    private JButton findBtn = new JButton(findImg);

    private Icon saveImg = Util.getIcon("/buttonSave.jpg");
    private JButton saveBtn = new JButton(saveImg);

    private Icon getImg = Util.getIcon("/buttonGet.jpg");
    private JButton getBtn = new JButton(getImg);

    private Icon modifyImg = Util.getIcon("/buttonModify.jpg");
    private JButton modifyBtn = new JButton(modifyImg);


    public Menu(Atm atm) {
        this.atm = atm;

        findBtn.setBounds(50, 100, 140, 50);
        this.add(findBtn);

        saveBtn.setBounds(50, 200, 140, 50);
        this.add(saveBtn);

        getBtn.setBounds(50, 300, 140, 50);
        this.add(getBtn);

        modifyBtn.setBounds(930, 100, 140, 50);
        this.add(modifyBtn);
        offBtn.setBounds(930, 200, 140, 50);
        this.add(offBtn);

        offBtn.addActionListener(this);
        saveBtn.addActionListener(this);
        getBtn.addActionListener(this);
        findBtn.addActionListener(this);
        this.setLayout(null);
        this.setOpaque(false);
    }

    @Override

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == offBtn) {
            System.out.println("11");
            atm.switchPanel("login");
        } else if (
                e.getSource() == saveBtn
        ) {
            atm.switchPanel("save");
            System.out.println("222");
        }else if (
                e.getSource() == findBtn
        ) {
            atm.switchPanel("find");
            System.out.println("222");
        }else if (
                e.getSource() == getBtn
        ) {
            atm.switchPanel("get");
            System.out.println("222");
        }

    }
}
